package org.jdcenter.server;

import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
/**
 * @author miao
 * @since 2008-11-18
 *
 */
public class PluginsURLClassLoader extends URLClassLoader{
	
	/** The value returned by {@link getURLs}. */
	private static final URL[] EMPTY_URL_ARRAY = {};

	   /**
	    * Create a classloader with the context classloader as parent
	    * 
	    * @param urls the urls
	    * @return the classloader
	    */
	public static PluginsURLClassLoader createClassLoader(URL... urls){
		return createClassLoader(Thread.currentThread().getContextClassLoader(), urls);
	}

	   /**
	    * Create a classloader
	    *
	    * @param parent the parent classloader
	    * @param urls the urls
	    * @return the classloader
	    */
	public static PluginsURLClassLoader createClassLoader(ClassLoader parent, URL... urls){
		return new PluginsURLClassLoader(urls, parent);
	}
	   
	   /**
	    * Construct a <tt>URLClassLoader</tt>
	    *
	    * @param urls   the URLs to load classes from.
	    */
	public PluginsURLClassLoader(URL[] urls){
		super(urls);
	}

	   /**
	    * Construct a <tt>URLClassLoader</tt>
	    *
	    * @param urls   the URLs to load classes from.
	    * @param parent the parent classloader.
	    */
	public PluginsURLClassLoader(URL[] urls, ClassLoader parent){
		super(urls, parent);
	}

	   /**
	    * Construct a <tt>URLClassLoader</tt>
	    *
	    * @param urls    the URLs to load classes from.
	    * @param parent  the parent classloader.
	    * @param factory the url stream factory.
	    */
	public PluginsURLClassLoader(URL[] urls, ClassLoader parent,
	                                     URLStreamHandlerFactory factory){
		super(urls, parent, factory);
	}

	   /**
	   * Return all library URLs
	   *
	   * <p>Do not remove this method without running the WebIntegrationTestSuite
	   * @return the urls
	   */
	public URL[] getAllURLs(){
		return super.getURLs();
	}

	   /**
	   * Return an empty URL array to force the RMI marshalling subsystem to
	   * use the <tt>java.server.codebase</tt> property as the annotated codebase.
	   *
	   * <p>Do not remove this method without discussing it on the dev list.
	   *
	   * @return Empty URL[]
	   */
	public URL[] getURLs(){
		return EMPTY_URL_ARRAY;
	}

}
